package testIO;

import java.io.*;

public class TestRead {
    public static void main(String[] args) throws IOException {
        //自动 reader.close()
        try (Reader reader = new FileReader("toRead.txt")) {
            while (true) {
                char[] cbuf = new char[3];
                int n = reader.read(cbuf);
                if (n == -1)
                    break;
                System.out.println("n = " + n);
                for (char a : cbuf)
                    System.out.println(a);
            }
        }
    }
    public static void main2(String[] args) throws IOException {
        Reader reader = new FileReader("toRead.txt");
        try {
            while(true) {
                char[] cbuf = new char[3];
                int n = reader.read(cbuf);
                if(n == -1)
                    break;
                System.out.println("n = " + n);
                for(char a : cbuf)
                    System.out.println(a);
            }
        } finally {
            reader.close();
        }
    }
    public static void main1(String[] args) throws IOException {
        //InputStream stream = new FileInputStream("toRead.txt");//字节流
        Reader reader = new FileReader("toRead.txt");//字符流
        while(true) {
            int c = reader.read();
            if(c == -1)
                break;
            System.out.println((char)c);
        }
    }
}
